package org.util;

/**
 * @author huangshen
 * @version 0.0.3
 * @description DateTime
 * @since 2022/1/9 22:56
 */
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateTime {
    public static final String YYYYMMDDHHMISS = "yyyyMMddHHmmss";
    public static final String YYYY_MM_DD_HH_MI_SS = "yyyy/MM/dd HH:mm:ss";

    public DateTime() {
    }

    private static String[] ParseDate(Date dDate) {
        try {
            String[] aResult = new String[7];
            Calendar ca = Calendar.getInstance();
            ca.setTime(dDate);
            aResult[0] = Integer.toString(ca.get(1));
            aResult[1] = Integer.toString(ca.get(2) + 1);
            aResult[2] = Integer.toString(ca.get(5));
            aResult[3] = Integer.toString(ca.get(11));
            aResult[4] = Integer.toString(ca.get(12));
            aResult[5] = Integer.toString(ca.get(13));
            aResult[6] = Integer.toString(ca.get(1) + 1);
            if (aResult[1].length() == 1) {
                aResult[1] = "0" + aResult[1];
            }

            if (aResult[2].length() == 1) {
                aResult[2] = "0" + aResult[2];
            }

            if (aResult[3].length() == 1) {
                aResult[3] = "0" + aResult[3];
            }

            if (aResult[4].length() == 1) {
                aResult[4] = "0" + aResult[4];
            }

            if (aResult[5].length() == 1) {
                aResult[5] = "0" + aResult[5];
            }

            return aResult;
        } catch (Exception var3) {
            return null;
        }
    }

    public static String[] getDateMsg(String sDateStr, int iHours) {
        try {
            sDateStr = sDateStr.replace('.', '/');
            sDateStr = sDateStr.replace('-', '/');
            SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            Date dDate = df.parse(sDateStr);
            if (iHours != 0) {
                long iNowDate = dDate.getTime();
                long iNewDate = iNowDate + (long) iHours * 60L * 60L * 1000L;
                dDate = new Date(iNewDate);
            }

            return ParseDate(dDate);
        } catch (Exception var8) {
            return null;
        }
    }

    public static String[] getDateMsg(Date dDate, int iHours) {
        try {
            if (iHours != 0) {
                long iNowDate = dDate.getTime();
                long iNewDate = iNowDate + (long) iHours * 60L * 60L * 1000L;
                dDate = new Date(iNewDate);
            }

            return ParseDate(dDate);
        } catch (Exception var6) {
            return null;
        }
    }

    public static Date getDate(String sDateTime) {
        try {
            if (sDateTime == null) {
                return null;
            } else {
                sDateTime = sDateTime.replace('.', '/');
                sDateTime = sDateTime.replace('-', '/');
                if (sDateTime.indexOf("/") == -1) {
                    sDateTime = "1900/1/1 " + sDateTime;
                }

                if (sDateTime.indexOf(":") == -1) {
                    sDateTime = sDateTime + " 0:0:0";
                }

                SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                return df.parse(sDateTime);
            }
        } catch (Exception var2) {
            return null;
        }
    }

    public static String getDateTimeValue(String sDateTime) {
        try {
            int iLength = sDateTime.length();
            String sDateTimeValue = null;
            if (iLength == 14) {
                sDateTimeValue = sDateTime.substring(0, 4) + "/" + sDateTime.substring(4, 6) + "/" + sDateTime.substring(6, 8) + " " + sDateTime.substring(8, 10) + ":" + sDateTime.substring(10, 12) + ":" + sDateTime.substring(12, 14);
            }

            if (iLength == 8) {
                sDateTimeValue = sDateTime.substring(0, 4) + "/" + sDateTime.substring(4, 6) + "/" + sDateTime.substring(6, 8);
            }

            if (iLength == 6) {
                sDateTimeValue = sDateTime.substring(0, 2) + ":" + sDateTime.substring(2, 4) + ":" + sDateTime.substring(4, 6);
            }

            return sDateTimeValue;
        } catch (Exception var3) {
            return sDateTime;
        }
    }

    public static String getDateTimeString(String sDateTime) {
        try {
            String[] aDateString = getDateMsg((Date) getDate(sDateTime), 0);
            return aDateString[0] + aDateString[1] + aDateString[2] + aDateString[3] + aDateString[4] + aDateString[5];
        } catch (Exception var2) {
            return sDateTime;
        }
    }

    public static String getDateString(String sDateTime) {
        try {
            String[] aDateString = getDateMsg((Date) getDate(sDateTime), 0);
            return aDateString[0] + aDateString[1] + aDateString[2];
        } catch (Exception var2) {
            return sDateTime;
        }
    }

    public static String getTimeString(String sDateTime) {
        try {
            String[] aDateString = getDateMsg((Date) getDate(sDateTime), 0);
            return aDateString[3] + aDateString[4] + aDateString[5];
        } catch (Exception var2) {
            return sDateTime;
        }
    }

    public static Date getDate() {
        try {
            Date dDate = new Date();
            return dDate;
        } catch (Exception var1) {
            return null;
        }
    }

    public static Date getStandDate(String sFormat, String sTimeStr) {
        try {
            SimpleDateFormat df = new SimpleDateFormat(sFormat);
            return df.parse(sTimeStr);
        } catch (Exception var3) {
            return null;
        }
    }

    public static String format(String sInputFormat, String sInputTime, String sOutputFormat) {
        try {
            Date dt = getStandDate(sInputFormat, sInputTime);
            return format(sOutputFormat, dt);
        } catch (Exception var4) {
            return null;
        }
    }

    public static String format(String sFormat, Date dt) {
        if (sFormat == null || sFormat.trim().length() == 0) {
            sFormat = "yyyy/MM/dd HH:mm:ss";
        }

        SimpleDateFormat df = new SimpleDateFormat(sFormat);
        return df.format(dt);
    }

    public static String format(Date dt) {
        try {
            return format("yyyy/MM/dd HH:mm:ss", dt);
        } catch (Exception var2) {
            return null;
        }
    }

    public static java.sql.Date convertToShort(Date dt) {
        try {
            return new java.sql.Date(dt.getTime());
        } catch (Exception var2) {
            return null;
        }
    }

    public static Timestamp convertToLong(Date dt) {
        try {
            return new Timestamp(dt.getTime());
        } catch (Exception var2) {
            return null;
        }
    }

    public static String format(long time, String format) {
        Date dt = new Date(time);
        return format(format, dt);
    }

    public static Timestamp convertToLong(String sInputFormat, String sInputTime) {
        try {
            return new Timestamp(getStandDate(sInputFormat, sInputTime).getTime());
        } catch (Exception var3) {
            return null;
        }
    }

    public static Timestamp convertToLong(String sInputTime) {
        try {
            return new Timestamp(getStandDate("yyyyMMddHHmmss", sInputTime).getTime());
        } catch (Exception var2) {
            return null;
        }
    }

    public static String[] getTime(int iIndex, int iDistance) {
        String[] aTemp = new String[]{"2002", "07", "02", "10", "10", "10"};

        try {
            Calendar cal = Calendar.getInstance();
            if (iIndex == 1) {
                cal.add(1, iDistance);
            } else if (iIndex == 2) {
                cal.add(2, iDistance);
            } else if (iIndex == 3) {
                cal.add(5, iDistance);
            } else if (iIndex == 4) {
                cal.add(11, iDistance);
            } else if (iIndex == 5) {
                cal.add(12, iDistance);
            } else if (iIndex == 6) {
                cal.add(13, iDistance);
            }

            aTemp[0] = cal.get(1) + "";
            aTemp[1] = getFullLength(cal.get(2) + 1, 2);
            aTemp[2] = getFullLength(cal.get(5), 2);
            aTemp[3] = getFullLength(cal.get(11), 2);
            aTemp[4] = getFullLength(cal.get(12), 2);
            aTemp[5] = getFullLength(cal.get(13), 2);
        } catch (Exception var4) {
            System.out.println(var4.toString());
            aTemp[0] = "2002";
            aTemp[1] = "07";
            aTemp[2] = "02";
            aTemp[3] = "02";
            aTemp[4] = "02";
            aTemp[5] = "02";
        }

        return aTemp;
    }

    public static String getFullLength(int iOral, int iLength) {
        int iIndex = ("" + iOral).length();
        if (iIndex > iLength) {
            return "" + iOral;
        } else {
            String sTemp = "" + iOral;

            for (int i = 0; i < iLength - iIndex; ++i) {
                sTemp = "0" + sTemp;
            }

            return sTemp;
        }
    }

    public static String[] getTime(int iIndex, int iDistance, String year, String month, String day, String hour, String minute, String second) {
        String[] aTemp = new String[]{"2002", "07", "02", "10", "10", "10"};

        try {
            Calendar cal = Calendar.getInstance();
            cal.set(1, Integer.parseInt(year));
            cal.set(2, Integer.parseInt(month) - 1);
            cal.set(5, Integer.parseInt(day));
            cal.set(11, Integer.parseInt(hour));
            cal.set(12, Integer.parseInt(minute));
            cal.set(13, Integer.parseInt(second));
            if (iIndex == 1) {
                cal.add(1, iDistance);
            } else if (iIndex == 2) {
                cal.add(2, iDistance);
            } else if (iIndex == 3) {
                cal.add(5, iDistance);
            } else if (iIndex == 4) {
                cal.add(11, iDistance);
            } else if (iIndex == 5) {
                cal.add(12, iDistance);
            } else if (iIndex == 6) {
                cal.add(13, iDistance);
            }

            aTemp[0] = cal.get(1) + "";
            aTemp[1] = getFullLength(cal.get(2) + 1, 2);
            aTemp[2] = getFullLength(cal.get(5), 2);
            aTemp[3] = getFullLength(cal.get(11), 2);
            aTemp[4] = getFullLength(cal.get(12), 2);
            aTemp[5] = getFullLength(cal.get(13), 2);
        } catch (Exception var10) {
            System.out.println(var10.toString());
            aTemp[0] = "2002";
            aTemp[1] = "07";
            aTemp[2] = "02";
            aTemp[3] = "02";
            aTemp[4] = "02";
            aTemp[5] = "02";
        }

        return aTemp;
    }

    public static long diffDate(Date date1, Date date2, int flag) {
        try {
            long lDiff = date1.getTime() - date2.getTime();
            if (flag == 1) {
                return lDiff / 3600000L;
            } else if (flag == 2) {
                return lDiff / 60000L;
            } else if (flag == 3) {
                return lDiff / 1000L;
            } else {
                return flag == 4 ? lDiff : 0L;
            }
        } catch (Exception var5) {
            return 0L;
        }
    }

    public static String addDateHour(Date dDate, int iHours) {
        try {
            if (iHours != 0) {
                long iNowDate = dDate.getTime();
                long iNewDate = iNowDate + (long) iHours * 60L * 60L * 1000L;
                dDate = new Date(iNewDate);
            }

            return format("yyyyMMddHHmmss", dDate);
        } catch (Exception var6) {
            return null;
        }
    }

    public static Date addDate(Date dDate, int iHours) {
        try {
            if (iHours != 0) {
                long iNowDate = dDate.getTime();
                long iNewDate = iNowDate + (long) iHours * 60L * 60L * 1000L;
                dDate = new Date(iNewDate);
            }

            return dDate;
        } catch (Exception var6) {
            return null;
        }
    }

    public static String add_Date(Date dDate, int iHours) {
        try {
            dDate = addDate(dDate, iHours);
            return format(dDate);
        } catch (Exception var3) {
            return null;
        }
    }

    public static void main(String[] args) {
        Date dt = new Date();
        System.out.println(dt);
        System.out.println(convertToShort(dt));
    }
}
